package com.yz.test.okhttp.controller;

import com.yz.test.okhttp.service.OptionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class OptionController {

    @Autowired
    private OptionService optionService;
    @Value(value = "${user.name}")
    private String username;

    @RequestMapping(value = "/trace")
    public String trace(){
        optionService.trace();
        return username;
    }

    @RequestMapping(value = "/monitor")
    public String monitor(){
        int i=9;
        while (i-->0){
            try {
                optionService.monitor();
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
        return "OK";
    }

    @RequestMapping(value = "/watch")
    public Object watch(){
        try {
            return optionService.watch("p1","p2");
        } catch (Exception e) {
            e.printStackTrace();
        }
        return "OK";
    }

    @RequestMapping(value = "/env")
    public Object env(){
        return username;
    }

}
